package leetcode.treeCode.week4.leetcode_98;

class Solution {
    private TreeNode prev = null;
    public boolean isValidBST(TreeNode root) {
        boolean dfs = dfs(root);
        return dfs;
    }
    private boolean dfs(TreeNode node){
        if (node == null) return true;
        // 左子树
        boolean b = dfs(node.left);
        if (!b) return false;
        // 中序遍历位置
        if (prev != null && prev.val >= node.val) {
            return false;
        }
        prev = node;
        // 右子树
        boolean b1 = dfs(node.right);
        if (!b1) return false;
        return true;
    }
}